﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Data.OleDb;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Web;
using Microsoft.JScript;
using System.Configuration;
using System.Data;
using Webchatting.Dal;
namespace Webchatting.Wcf
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class WCFService
    {
        #region 加载好友列表
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public string LoadFriends(string RUId)
        {
            OperationFriends OperateAboutFriends = new OperationFriends();
            return OperateAboutFriends.GetFriendsList(RUId);
        }
        #endregion


        #region 加载群列表
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public string LoadGroups(string RUId)
        {
            OperationGroup OperateAboutGroup= new OperationGroup();
            return OperateAboutGroup.GetGroupList(RUId);
        }
        #endregion


        //#region 加载群成员
        //[OperationContract]
        //[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //public string LoadGroups(string GId)
        //{
        //    OperationGroup OperateAboutGroup = new OperationGroup();
        //    return OperateAboutGroup.GetGroupMumList(GId);
        //}
        //#endregion


        #region 发送好友消息
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public int SendMessagesService(int receiveRUId, int sendRUId, string msgContent, string RUNickName)
        {
           // Console.Write(RUNickName);
            SendMessages SendMessages = new SendMessages();
            
            SendMessages.SendFriendsMessagesMethod(receiveRUId, sendRUId, GlobalObject.unescape(msgContent), RUNickName);
            return 1;
        }
        #endregion


        #region 接收好友消息
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public string ReceiveMessagesService(string receiveRUId, string sendRUId, string isUpdateChatMessages)
        {
            ReceiveMessages ReceiveMessages = new ReceiveMessages();
            return ReceiveMessages.ReceiveFreindsMessagesMethod(receiveRUId, sendRUId, isUpdateChatMessages);
        }
        #endregion


        #region 接收好友消息(ReadOnly)
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public string ReceiveMessagesReadOnlyService(string receiveRUId, string sendRUId, string isUpdateChatMessages)
        {
            ReceiveMessages ReceiveMessages = new ReceiveMessages();
            return ReceiveMessages.ReceiveFriendsMessagesReadOnly(receiveRUId, sendRUId, isUpdateChatMessages);
        }
        #endregion


        #region 发送群消息
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public int SendGroupMessagesService(int receiveGroupId, string msgContent, int sendRUId, string RUGroupRemarkName)
        {
           // Console.Write(receiveGroupId+" "+sendRUId+" "+msgContent+" "+RUGroupRemarkName);
            SendMessages SendMessages = new SendMessages();

            SendMessages.SendGroupMessagesMethod(receiveGroupId, GlobalObject.unescape(msgContent),sendRUId,  GlobalObject.unescape(RUGroupRemarkName));
           
            return 1;
        }
        #endregion


        #region 接收群消息
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public string ReceiveGroupMessagesService(int receiveGroupId,int RUId)
        {
            ReceiveMessages ReceiveMessages = new ReceiveMessages();
            return ReceiveMessages.ReceiveGroupsMessagesMethod(receiveGroupId.ToString(),RUId.ToString());
        }
        #endregion


        #region 发送聊天室消息
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public int SendChattingRoomMessagesService(int BUId, string msgContent, string BUNickName)
        {
            OperationBU SendMessages = new OperationBU();

            return SendMessages.SendChattingRoomMessagesMethod(BUId,  GlobalObject.unescape(msgContent),GlobalObject.unescape(BUNickName));
            
        }
        #endregion


        #region 接收聊天室消息
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public string ReceiveChattingRoomMessagesService(DateTime RecieveTime)
        {
            OperationBU ReceiveMessages = new OperationBU();
            return ReceiveMessages.RecieveChattingRoomMessagesMethod(RecieveTime);
        }
        #endregion
       
        
        #region 添加好友
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public string AddFriend(string RUId, string FRUId)
        {
            return "";
        }
        #endregion

       
        #region 删除好友
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public string DeleteFriendsService(string RUId, string FRUId)
        {
            OperationFriends OperateAboutFriends = new OperationFriends();
            OperateAboutFriends.DeleteFriend(RUId, FRUId);
            return "ok";
        }
        #endregion


        #region 检测好友是否在线
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public string CheckOnlineFriends()
        {
            return "";
        }
        #endregion


        //#region 加载群列表
        //[OperationContract]
        //[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //public string LoadGroups(string RUId)
        //{
        //    OperationGroup OperateAboutGroup = new OperationGroup();
        //    return OperateAboutGroup.GetGroupList(RUId);
        //}
        //#endregion
        
    }
}
